home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 038a / qbvideo.zip / VIDEO.ASM
Assembly Source File  |  1991-06-19  |  17KB  |  400 lines

  1. ;«RM82»«TS8,16,24,32,40,48,56,64»
  2. ; Updated 11/20/90
  3.  
  4. ;=======================================================================
  5. ;   Copyright (C) Copr. 1990 by Sidney J. Kelly
  6. ;                   All Rights Reserved.
  7. ;           Sidney J. Kelly
  8. ;           150 Woodhaven Drive
  9. ;           Pittsburgh, PA 15228
  10. ;           home phone 412-561-0950 (7pm to 9:30pm EST)
  11. ;-----------------------------------------------------------------------
  12. ; Function prototype in QBASIC
  13. ; DECLARE FUNCTION VideoStat% ()
  14. ;
  15. ; VideoStatus Analyzer
  16. ; Program returns video information for use by QBASIC
  17. ; returns highest level of SCREEN mode supported by the Hardware.
  18. ; Returns information about the PRIMARY display only
  19. ; This routine with a select case, can tell you how many display pages
  20. ; are available in text mode, SCREEN 0:
  21. ; VGA has 8 pages
  22. ; EGA with > 64kb has 8 pages
  23. ; EGA with 64kb has 4 pages
  24. ; CGA has 4 pages
  25. ; MONO has 1 pages
  26. ; HERC has 1 page in SCREEN 0, 2 pages in SCREEN 3
  27. ;
  28. ; Exceptions:
  29. ; MCGA color returns a mode 11, so can contrast w/ VGA
  30. ; HERC w/o MSHERC.COM reports a -3 so you can tell user to correct matters
  31. ; COMPAQ with CGA reports -2 so can force use of monchrome attributes.
  32. ; EGA's with CGA diplays report -8 if have only 64kb of memory
  33. ; EGA's with ECD display report  8 if have only 64kb of memory
  34. ;
  35. ; Returns:
  36. ; Mono         =   0
  37. ; CGA          =   2
  38. ; PGA          =   2   (Untested, assume PGA would be treated as CGA)
  39. ; COMPAQ - CGA =  -2   to tell that user may have a single color display
  40. ; HERC         =   3   if have HERC and MSHERC.COM
  41. ; HERC         =  -3   if have HERC but w/o MSHERC.COM
  42. ; AT&T         =   4,  but only if have just CGA display, not EGA or VGA
  43. ;     Microsoft QuickC/C makes Olivetti EGA and VGA return a separate code.
  44. ;     I don't know why anyone would care if the EGA/VGA emulation were
  45. ;     good.
  46. ;
  47. ; EGA64        =   8   Because resolution limited for 64k EGA
  48. ; EGA64 w/CGA  =  -8   Because resolution limited to CGA modes
  49. ; EGA          =   9   Have minimum of 128kb of video ram
  50. ; EGA w/CGA    =  -9   Since resolution limited to CGA modes
  51. ; MCGA         =  11   If have an analog color display
  52. ; MCGA         = -11   If have an EGA ECD digital color display, since
  53. ;                      resolution of this display is limited to EGA modes
  54. ; VGA          =  13
  55. ; EGA/VGA mono =  10   I guess will catch MCGA mono too
  56. ;
  57. ; Version 0.92
  58. ;
  59. ; Tested:     CGA, HERC clone, EGA mono, EGA color, VGA color, COMPAQ CGA,
  60. ;             VGA clone, EGA clone (Paradise clone, ATI EGA Wonder), AT&T 6300
  61. ; Not tested: PGA, VGA monochrome, MCGA (color or monochrome)
  62. ;=======================================================================
  63.  
  64. DOSSEG          ;I have had problems unless this is used
  65. .model medium   ;I use QUICK C / QUICK ASM which uses MASM 5.1 simplified
  66. .code           ;directives
  67.  
  68.     public VIDEOSTAT
  69.  
  70. HERC_PORT       Equ     03bah       ; Herc display status port
  71. COMPAQ          DB     'COMPAQ'     ; BIOS ID string in COMPAQ's
  72. COMPAQ_LEN      Equ     6           ; length of string
  73.  
  74. ;Following is commented out because alternative method is faster
  75. ;ATT             DB     'OLIVETTI'   ; BIOS ID string for OLIVETTI/AT&T
  76. ;ATT_LEN         Equ     8           ; length of string
  77.  
  78. ; Please do not remove
  79. Copyright       DB    13,10,'Copyright Copr. (C) 1990 Sidney J. Kelly',13,10
  80. Copyright1      DB    'All Rights Reserved',13,10,26
  81.  
  82. EVEN
  83. VIDEOSTAT   PROC far
  84.      Push    BP                 ; save BP because old PC Video BIOS
  85.                                 ; didn't necessarily preserve this
  86.      Push    DI                 ; QBASIC requires these 2 to be saved
  87.      Push    SI
  88.                                 ; this just tests for primary display
  89. vgatest:                        ; because that is all QBASIC cares about
  90.      Mov     AX,1A00h
  91.      Mov     BX,10h             ; Test for VGA adapter
  92.      Int     10h
  93.      Cmp     AL,1Ah             ; If VGA adapter exists, it returns AL=1Ah
  94.      Jne     egatest            ; VGA does not exist so test for EGA
  95.                 ; Else VGA exists, primary display info
  96.      Cmp     BL,8               ; routine returns primary display in BL
  97.      Jne     @F
  98.      Jmp     Short  vga_color   ; VGA color exists. This does not test
  99.                                 ;  if VGA adapter clone is in emulation
  100.                                 ;  mode, such as HERC emulation
  101.                                 ;  because QBASIC does not check
  102.                                 ;  for this either.
  103. @@:
  104.      Cmp     BL,7
  105.      Jne     @f
  106.      Jmp     vga_mono           ; VGA mono exists, no effort is made to
  107.                 ; distinguish between VGA, EGA or MCGA mono
  108. @@:
  109.      Cmp     BL,11
  110.      Jne     @f
  111.      Jmp     vga_mono           ; MCGA mono exists
  112. @@:
  113.      Cmp     BL,12
  114.      Jne     @f
  115.      Jmp     Short mcga_color   ; MCGA analog color exists
  116. @@:
  117.      Cmp     BL,10
  118.      Jne     @f
  119.      Jmp     Short mcga_ecd     ; MCGA w/EGA display (untested)
  120. @@:
  121.      Cmp     BL,4               ; EGA color screen found, we have to
  122.      Jne     @f                 ; test if EGA is attached to ECD
  123.      Jmp     Short egatest      ; monitor or just plain CGA monitor
  124. @@:
  125.      Cmp     BL,5
  126.      Jne     @f
  127.      Jmp     Short vga_mono     ; EGA mono screen found
  128. @@:
  129.      Cmp     BL,2
  130.      Jne     @F
  131.      Jmp     Short att_test     ; CGA color found, test for which type
  132. @@:
  133.      Cmp     BL,1
  134.      Jne     @f
  135.      Jmp     herctest           ; MDA mono found
  136. @@:
  137.      Cmp     BL,6               ; test for PGA, treat as a CGA
  138.      Jne     @f
  139.      Jmp     cga                ; I guess this should work, untested
  140.  
  141. @@:                             ; With everything else
  142.      Jmp     unknown            ; merely assume can do normal b&w text
  143.  
  144. egatest:
  145.      Mov     AX,1200h
  146.      Mov     BX,10h
  147.      Int     10h
  148.      Cmp     BL,10h             ; EGA changes BL from 10h
  149.      Je      cgatest
  150.  
  151.      Mov     DX,BX              ; Save BX temporarily in DX
  152.      Xor     BX,BX
  153.      Mov     ES,BX
  154.      Test    ES:Byte Ptr [487h],1000b  ;EGA active?, bit 3 of 0040:0087 set?
  155.      JZ      EGA_active         ; if bit clear, then EGA is active
  156.      Jmp     Short cgatest      ; else if EGA not active (primary) check CGA
  157.  
  158. EGA_active:
  159.      Mov     BX,DX              ; get former value back from CX
  160.      Or      BH,BH              ; if BH = 1 then have MONO display
  161.      JZ      ega_color          ; else have color display
  162.      Jmp     Short vga_mono     ; treat as a VGA mono
  163.  
  164. vga_color:
  165.      Mov     AX,13              ; max screen mode is QBASIC SCREEN 13
  166.      Jmp     Quit
  167.  
  168. mcga_color:
  169.      Mov     AX,11              ; near max screen mode is QBASIC SCREEN 11
  170.      Jmp     Quit               ; MCGA can do SCREEN 13 too, but not 12.
  171.  
  172. mcga_ecd:
  173.      Mov     AX,-11             ; a warning that MCGA has EGA display
  174.      Jmp     short Quit         ; attached (Untested)
  175.  
  176. ega_color:
  177. ;*********** Based on information returned by AH 12h, BL 10h of INT 10h,
  178. ;*********** this routine reads the EGA Sense switches stored in CL
  179. ;*********** to see if really have a primary monitor that can do EGA graphics.
  180. ;*********** If do not have an ECD/multisync display, report a -9.
  181. ;*********** If have a 64kb EGA reports 8 if have ECD or -8 if have CGA
  182. ;*********** It is unclear if this will work on all clone EGA's.
  183. ;*********** It works with a VGA clone and ATI EGA Wonder as well as an
  184. ;*********** ACER EGA clone.
  185. ;*********** CL information derived from RAM memory at 0040:0088h
  186. ;***********
  187. ;*********** Source of CL information:
  188. ;*********** Ferro, "Programmer's Guide to the EGA and VGA Cards,"
  189. ;*********** (Addison-Wesley 1988), page 337.  Yet on page 473 says you can't
  190. ;*********** tell what CL will report.
  191. ;*********** Similar information hidden in Wilton, "Programmer's Guide to
  192. ;*********** PC & PS/2 Video Systems" (Microsoft 1987), page 520.
  193. ;***********
  194. ;*********** Partial information set forth in Phoenix's "System Bios for
  195. ;*********** PC/XT/AT Computers and Compatibles (Addison-Wesley 1989)
  196. ;*********** page 243 (which states that VGA's follow this too)
  197. ;***********
  198. ;*********** Wilton's routine also appears in other books, e.g.
  199. ;*********** Tischer, "PC System Programming for Developers" (ABACUS 1989)
  200. ;*********** page 542
  201. ;***********
  202. ;*********** See also, Woram, "PC Configuration Book" (Bantam 1987),
  203. ;***********   pages 279-280 Provides listing of IBM official switch
  204. ;***********   settings which does not seem to match anything
  205. ;***********   in the above two books.
  206. ;***********
  207. ;***********   CL returns on good clones:
  208. ;***********     EGA inactive w/ MDA primary   =  00h, 01h, 02h, 03h
  209. ;***********     EGA inactive w/ CGA primary   =  04h, 05h
  210. ;***********     EGA active w/ CGA             =  06h, 07h
  211. ;***********     EGA active w/ ECD in CGA mode =  08h
  212. ;***********     EGA active w/ ECD             =  09h
  213. ;***********     EGA active w/ MDA mono        =  0Bh, 0Ah
  214.  
  215.  
  216.      Cmp     CL,9               ; read EGA Sense switches to see if
  217.                 ; have ECD display and not a CGA display
  218.      JE      ega1
  219.      Mov     AX,-9              ; report have a CGA type display
  220.      Or      BL,BL              ; check if BL=0, i.e. 64kb Memory
  221.      JNZ     @f                 ; nope so quit
  222.      Inc     AX                 ; report have a CGA display w/ 64kb Memory
  223. @@:
  224.      Jmp     short Quit         ; with an EGA adapter
  225.  
  226. ega1:
  227.      Mov     AX,9               ; max screen mode is QBASIC SCREEN 9
  228.      Or      BL,BL              ; check if BL = 0, i.e. 64kb memory
  229.      JNZ     @f                 ; nope, so quit
  230.      Dec     AX                 ; report have EGA w/ ECD display
  231.                                 ; but only 64KB memory (makes 9 an 8)
  232. @@:
  233.      Jmp     Short Quit
  234.  
  235. vga_mono:
  236.      Mov     AX,10              ; max screen mode is QBASIC SCREEN 10
  237.      Jmp     Short Quit         ; may also be a MCGA or EGA mono too.
  238.                                 ; since QBASIC does not distinguish
  239.                                 ; I don't either
  240. cgatest:
  241.      Xor     AX,AX
  242.      Mov     ES,AX
  243.      Mov     BX,ES:[0463h]      ; check if MONO port in use
  244.      Cmp     BL,0B4h
  245.      Je      herctest           ; this test looks for Mono port address
  246.  
  247. att_test:
  248. ;******* The AT&T CGA is just a CGA that responds to a special mode set
  249. ;******* command.  Mode 48h is equivalent to SCREEN 4.  It is possible
  250. ;******* to load BIOS ram with this screen mode and fool QBASIC.  Try it and
  251. ;******* you will get some weird displays on non-AT&T displays.
  252. ;******* Unknown if that "gamemanship" may hurt your monitor.
  253. ;*******
  254. ;******* Cannot merely attempt to change to mode &H48 to test for AT&T
  255. ;******* because some old CGA's (e.g. Tecmar Color Graphics Card) will let you
  256. ;******* change mode number to anything you try.  However HERC clones,
  257. ;******* EGA clones and VGA clones will only allow a change to a supported
  258. ;******* video mode so such a test would work with them, but would be
  259. ;******* worthless unless you could be confident that all CGA's were new.
  260.  
  261.      Mov     AX,0F000h          ; Get ROM ID segment
  262.      Mov     ES,AX              ; Store segment in ES
  263.      CLD                        ; clear the direction flag
  264.      Push    DS                 ; Save DS
  265.      Mov     AX,CS
  266.      Mov     DS,AX              ; set DS = to CS
  267.  
  268.      Assume  DS:@code
  269.  
  270.      comment        |*
  271.             ; this is the long form routine, using full name
  272.      Mov     DI,0C050h          ; point DI at ROM
  273.      Mov     SI,OFFSET ATT      ; DS:SI points to  "OLIVETTI".
  274.      Mov     CX,ATT_LEN         ; CX has length of "OLIVETTI".
  275.      REPE    CMPSB              ; ES:DI destination, DS:SI source
  276.      Jne     compaq_test        ; if no change test for COMPAQ
  277.                  |*
  278.                      ; faster version
  279.                      ; Source:  XMS.SYS version 2.06 MASM source
  280.      Cmp     ES:[0C05h],'LO'    ; look for byte reversed 'OL' at FC00:0050h
  281.                      ; in memory letters are reversed
  282.      Jne     compaq_test    ; COMPAQ not found
  283.  
  284. att_found:
  285.      ; program assumes that if a CGA is active on an AT&T
  286.      ; that built-in adapter is in use.
  287.  
  288.      Pop     DS                 ; restore DS
  289.  
  290.      Assume  DS:@data
  291.  
  292.      Mov     AX,4               ; max screen mode is QBASIC SCREEN 4
  293.      Jmp     Short Quit
  294.  
  295. compaq_test:
  296.      ; Purpose of this test is to allow other routines to know if
  297.      ; "snow" testing is necessary, as well as to tell programmer
  298.      ; to use mono attributes in program rather than color attributes
  299.      ; which would confuse the viewer of a COMPAQ single color display.
  300.      ; source: XMS.SYS Version 2.06 MASM Source Code
  301.  
  302.      Mov     DI,0FFEAh          ; Get ID offset & store in DI
  303.      Mov     SI,OFFSET COMPAQ   ; DS:SI points to  "COMPAQ".
  304.      Mov     CX,COMPAQ_LEN      ; CX has length of "COMPAQ".
  305.      REP     CMPSB              ; ES:DI destination, DS:SI source
  306.      Pop     DS                 ; restore DS
  307.  
  308.      Assume  DS:@data
  309.  
  310.      ; Program assumes that if a CGA is active on a COMPAQ
  311.      ; that built-in single color display is in use because
  312.      ; even though it does not have color it has better
  313.      ; text resoluton.
  314.      Mov     AX,-2              ; assume found COMPAQ CGA mode
  315.                 ; to tell us that user likely has a
  316.                 ; single color display
  317.      JE      found_compaq       ; if match found
  318.  
  319. cga:                            ; Normal CGA
  320.      Mov     AX,2               ; max screen mode is QBASIC SCREEN 2
  321.  
  322. found_compaq:
  323.      Jmp     Short Quit
  324.  
  325. herctest:
  326.      ;*****Main Herc test entry point****
  327.      ; Herc display changes Vertical retrace bit during vertical retrace
  328.      ; however normal MDA display does not.
  329.      ; Source for HERC test only:
  330.      ; Hercules Computer Technology, Inc. and Doty,
  331.      ; "Programmer's Guide to Hercules Graphics Cards"
  332.      ; (Addison-Wesley 1988) page 138.
  333.      ; Similar routines have been  published in PC Magazine
  334.      ; and Young, "Inside DOS: A Programmer's Guide", (Sybex 1990)
  335.      ; page 178, as well as Young's book on OS/2.
  336.      ;
  337.      ; No effort is made to test for Herc INCOLOR or any other HERC
  338.      ; displays since QBASIC would not use the information.
  339.      ; If you must have it, see Doty or Wilton's books listed above.
  340.  
  341.                                 ; test the HERC_Port
  342.      Mov     DX,HERC_PORT       ; load DX with display status port
  343.                                 ; a Read-only port
  344.      Xor     BX,BX              ; clear counter
  345.      IN      AL,DX              ; read port
  346.      And     AL,80h             ; mask off every bit but bit 7
  347.      Mov     AH,AL              ; store in AH original status of bit
  348.      Mov     CX,8000h           ; load loop counter
  349.  
  350. herc1:
  351.      IN      AL,DX              ; read byte
  352.      And     AL,80h             ; clear everything but bit 7
  353.      Cmp     AL,AH              ; keep testing for change in bit 7
  354.      Je      herc2
  355.      Inc     BL                 ; for every change Inc BL
  356.      Cmp     BL,12              ; check routine found vertical
  357.                                 ; retrace changed 12 times
  358.      JA      Test_4_MSHERC      ; found a herc so test for MSHERC.COM
  359.  
  360. herc2:
  361.      Loop    herc1              ; Herc display not found
  362.  
  363. unknown:                        ; Handles mono displays too
  364.      Xor     AX,AX              ; return a 0 if just normal text display
  365.  
  366. EVEN
  367. Quit:
  368.      Pop     SI                 ; restore saved registers
  369.      Pop     DI
  370.      Pop     BP
  371.      Ret
  372.  
  373. Test_4_MSHERC:
  374.      Mov     AX,0EF00h          ; test for MSHERC.COM
  375.      Int     10h
  376.      Mov     AX,3               ; Assume max screen mode is QBASIC SCREEN 3
  377.      Cmp     DX,0100h           ; **this is an undocumented call and may
  378.                                 ; change ******!!!!!
  379.      JE      Have_MSHerc        ; if equal then MSHERC.COM is installed
  380.      Mov     AX,-3              ; else report MSHERC.COM is not installed
  381.                 ; return -3
  382. Have_MSHerc:
  383.      Jmp     Short Quit
  384.  
  385. VIDEOSTAT       ENDP
  386. END
  387.  
  388. ;----------------------------------------------------------------------
  389. ; If you read this far, you are a scholar.  If you really want a good
  390. ; video book I would suggest that you buy Michael Abrash's On Graphics
  391. ; book about EGA/VGA display's, published by QUE, very advanced.
  392. ; For useful information,-- what does this port do--, for all display
  393. ; types, Wilton's book is very good.  Ferro's book has more specific
  394. ; EGA/VGA information but book is a little disorganized.
  395. ;           Sidney J. Kelly
  396. ;           150 Woodhaven Drive
  397. ;           Pittsburgh, PA 15228
  398. ;           home phone 412-561-0950 (7pm to 9:30pm EST)
  399. ;----------------------------------------------------------------------
  400.